/*
 * All rights Reserved, Designed By baowei
 *
 * 注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的
 */
package com.xyy.scaffoldweb;

import com.xyy.scaffoldcommon.dto.UserDTO;
import com.xyy.scaffolddao.dataobject.UserDO;
import com.xyy.scaffoldservice.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : jiazhuang
 * @since : 2023/6/8, Thu
 **/
@RestController
@Api(tags = "用户数据接口")
public class UserController {

    @Resource
    UserService userService;

    @ApiOperation(value = "查询用户", notes = "根据姓名查询用户")
    @GetMapping("/user/{name}")
    public String queryUserByName(@PathVariable String name) {
        UserDO userDO = userService.findUserByName(name);
        System.out.println(userDO);
        return "查找的用户为：" + name;
    }

    @ApiOperation(value = "新增用户", notes = "根据用户名和ID添加新用户")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "userName", value = "用户名",
                    required = true),
            @ApiImplicitParam(paramType = "query", name = "userID", value = "用户ID",
                    required = true)
    })
    @PostMapping("/user")
    public String addUser(@RequestParam String userName, @RequestParam Integer userID) {
        userService.insertUser(userName);

        return "新增用户：" + userName + "，ID：" + userID;
    }

    @ApiOperation(value = "修改用户信息", notes = "更新用户信息")
    @PutMapping("/user")
    public String updateUser(@RequestBody UserDTO userDTO) {
        return userDTO.toString();
    }
}
